<?php defined('SYSPATH') OR die('No direct access allowed.');

class Channel_Controller extends Master_Member_Controller 
{
		
	public function ajax_vote($owner_id, $profile_id, $channel_id) {
		if(request::is_ajax())
	    {
	    	$this->auto_render=false;
	    	$ajax = new ISS_Ajax();

	    	$votes = new Votes_Model;
	    	$votes->vote_channel($owner_id, $profile_id, $channel_id);

	    	$tag = 'vote';
	    	$script = 'alert("ดำเนินการโหวตเรียบร้อยแล้ว");';
	    	$ajax->addExecJScript($tag, $script);
	    	
	    	$tag = 'close_popup';
	    	$script = 'closePopUp();';
	    	$ajax->addExecJScript($tag, $script);
	    	
	    	$tag = 'refresh';
	    	$script = 'location.reload(true)';
	    	$ajax->addExecJScript($tag, $script);
	    	
	    	echo json_encode($ajax->getHtmlAjax());
	    }
	}
	
	public function request_vote($owner_id, $profile_id, $channel_id) {
		$view = new View("vote/vote_channel");
        $view->title = "สมาชิก - โหวตสถานีเพลง";

        $votes = new Votes_Model;
        
        $form = array (
        			'owner_id' => $owner_id,
        			'profile_id' => $profile_id,
					'channel_id'    => $channel_id,
        			'title'   => '',
				);
		$form['title'] = $votes->get_channel_title($owner_id, $channel_id);
				
        $view->is_channel_limited = $votes->is_channel_limited($profile_id);
        $view->is_channel_voted = $votes->is_channel_voted($owner_id, $profile_id, $channel_id);
		$view->form = $form;
        $view->render(TRUE);		
	}

}
